// JavaScript Document
function hideform()
{
	document.getElementById("search_form").style.display = "none";
	document.getElementById("continue_search").innerHTML = '<a href="#" id="show" >Tiếp tục tìm kiếm</a>';
}

function CreateXMLHttpRequest()
{
	if(window.XMLHttpRequest)	
	{
		return new XMLHttpRequest;
	}
	else if(window.ActiveXObject)
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function HandleResponseFromServer()
{
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		var Result = xmlHttp.responseText;
		document.getElementById("divCategoryID").innerHTML = Result;
	}
}

function GetCategoryByField(fieldID,catid)
{
	document.getElementById("divCategoryID").innerHTML = "<img src='../images/loader.gif'/>";
	xmlHttp = CreateXMLHttpRequest();
	xmlHttp.onreadystatechange = HandleResponseFromServer;
	var serverURL = "../common/ResponseFromServer.php";
	var params = "fieldid=" + fieldID;
	params += "&catid=" + catid;
	xmlHttp.open("POST",serverURL,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length",params.length);
	xmlHttp.setRequestHeader("Connection","close");
	xmlHttp.send(params);
}

function GetBookByKey(keyword,page)
{
	xmlHttp = CreateXMLHttpRequest();
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			var Result = xmlHttp.responseText;
			document.getElementById("search_result").innerHTML = Result;
			document.getElementById("search_form").style.display = "none";
		}
	}
	
	var serverURL = "ResponseFromServer.php";
	serverURL += "?keysearch=yes";
	serverURL += "&bookname=" + keyword + "&page=" + page;
	serverURL += "&t=" + new Date().getTime();
	xmlHttp.open("GET",serverURL,true);	
	xmlHttp.send(null);
}

									/*Tra tu khoa cua nguoi dung ra giao dien*/
function ShowBookName(bookname)
{
	document.getElementsByName("txtBookName")[0].value = bookname;
}

function ShowUserName(username)
{
	document.getElementsByName("txtUserName")[0].value = username;
}

function ShowBookType(booktypeid)
{
	document.getElementsByName("BookTypeID")[0].value = booktypeid;
}

function ShowAuthor(author)
{
	document.getElementsByName("txtAuthor")[0].value = author;
}

function ShowPublisher(publisher)
{
	document.getElementsByName("txtPublisher")[0].value = publisher;
}

function ShowFieldID(fieldid)
{
	document.getElementsByName("FieldID")[0].value = fieldid;
	GetCategoryByField(fieldid,0);
}

function sleep(milisecond)
{
	var a = new Date();
	var b = null;
	do
	{
		b = new Date();
	}while(b - a < milisecond);
}

function ShowCategoryID(fieldid, catid)
{
	GetCategoryByField(fieldid,catid);
}

function ShowMana(isgreaterthan,mana)
{
	document.getElementsByName("isGreaterthan")[0].value = isgreaterthan;
	document.getElementsByName("txtMana")[0].value = mana;
}

function ShowMinRatingPoint(point)
{
	document.getElementsByName("txtMinRatingPoint")[0].value = point;
}

function ShowMaxRatingPoint(point)
{
	document.getElementsByName("txtMaxRatingPoint")[0].value = point;
}

function ShowDescription(des)
{
	document.getElementsByName("txtDescription")[0].innerHTML = des;
}

function resetform()
{
	var fieldid = document.getElementsByName("fieldoption")[0].value;
	GetCategoryByField(fieldid,0);
}

